﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualPress.Infrastructure.Entities.Repository;
using VirtualPress.Infrastructure.Entities.Enum;

namespace VirtualPress.Infrastructure.Entities.Entity
{
    public class MagazineItem : 
        IAccessible<T_MagazineItem, MagazineItem>,
        ILogicEntity<T_MagazineItem, MagazineItem>
    {
        #region Fileds
        public int Id { get; set; }
        /// <summary>
        /// 所属期刊
        /// </summary>
        public int PeriodicalId { get; set; }
        /// <summary>
        /// 本期刊号
        /// </summary>
        public string Manuscriptcode { get; set; }

        public DateTime PublishDate { get; set; }
        public DateTime CreateDate { get; set; }
        public string CoverImage { get; set; }
        public string Information { get; set; }
        public JournalItemStatus Status { get; set; }
        /// <summary>
        /// 页面所在基础地址
        /// </summary>
        public string PagePath { get; set; }
        #endregion

        protected override void Covariant(T_MagazineItem model)
        {
            if (model != null)
            {
                this.CoverImage = model.CoverImage;
                this.CreateDate = model.CreateDate;
                this.Id = model.Id;
                this.Information = model.Information;
                this.Manuscriptcode = model.Manuscriptcode;
                this.PagePath = model.PagePath;
                this.PeriodicalId = model.PeriodicalId;
                this.PublishDate = model.PublishDate;
                this.Status = (JournalItemStatus)model.Status;
            }
        }

        protected override T_MagazineItem Inverter(MagazineItem model)
        {
            if (model != null)
            {
                return new T_MagazineItem()
                {
                    CoverImage = model.CoverImage,
                    CreateDate = model.CreateDate,
                    Id = model.Id,
                    Information = model.Information,
                    Manuscriptcode = model.Manuscriptcode,
                    PagePath = model.PagePath,
                    PeriodicalId = model.PeriodicalId,
                    PublishDate = model.PublishDate,
                    Status = (int)model.Status
                };
            }
            return null;
        }

        public MagazineItem Set(T_MagazineItem dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
